package com.dht.xiao.jianye.command.base.exception;

import android.text.TextUtils;

/**
 * @author :      fangbingran
 * @aescription : todo(这里用一句话描述这个类的作用)
 * @date :        2019/06/06  10:48
 */
public class DlcSerialPortException extends ApiException {
    /**
     * -1失败，-2超时，-3硬件错误
     */
    private int serialPortStatus;
    private String deviceAddress;
    private int baudRate;

    public DlcSerialPortException(ApiException message) {
        super(message.getCode(), message.getMessage());
        if (TextUtils.equals(ApiExceptionCode.SERIAL_PORT_READ_OUT_TIME_ERROR, message.getCode())) {
            setSerialPortStatus(-2);
        } else if (TextUtils.equals(ApiExceptionCode.SERIAL_PORT_ERROR, message.getCode())) {
            setSerialPortStatus(-3);
        } else {
            setSerialPortStatus(-1);
        }
    }

    public DlcSerialPortException(String code, String message) {
        super(code, message);
        if (TextUtils.equals(ApiExceptionCode.SERIAL_PORT_READ_OUT_TIME_ERROR, code)) {
            setSerialPortStatus(-2);
        } else if (TextUtils.equals(ApiExceptionCode.SERIAL_PORT_ERROR, code)) {
            setSerialPortStatus(-3);
        } else {
            setSerialPortStatus(-1);
        }
    }

    public DlcSerialPortException(String deviceAddress, int baudRate, ApiException dLCException) {
        super(dLCException.getCode(), dLCException.getMessage());
        setDeviceAddress(deviceAddress);
        setBaudRate(baudRate);
    }

    public int getSerialPortStatus() {
        return serialPortStatus;
    }

    public void setSerialPortStatus(int serialPortStatus) {
        this.serialPortStatus = serialPortStatus;
    }

    public String getDeviceAddress() {
        return deviceAddress;
    }

    public void setDeviceAddress(String deviceAddress) {
        this.deviceAddress = deviceAddress;
    }

    public int getBaudRate() {
        return baudRate;
    }

    public void setBaudRate(int baudRate) {
        this.baudRate = baudRate;
    }
}

